//
//  HouseDetailViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/9/8.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "HouseDetailViewController.h"
#import "RentVieitor.h"
#import "RVHeadView.h"
#import "Starview.h"
#import "FangDetailModel.h"
#import "PlotDetail.h"
#import "MJRefresh.h"
#import "LoginViewController.h"
#import "BrokerModel.h"
#import "UIImageView+WebCache.h"


@interface HouseDetailViewController ()<UIScrollViewDelegate,UIGestureRecognizerDelegate>

@end

@implementation HouseDetailViewController {
    
    CGFloat Y;
    UIScrollView *_scrollView;
    UIView *navgationView;
    NSArray *facilityArray;
    
    UIView *markView;//笼罩视图
    UIView *subscribeView;//预约视图
    UIView *successView;
    RVHeadView *_headView;
    
}

- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = BackgroundColor;
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, -20, KWidth, KHeight-45+20)];
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.delegate = self;
    [_scrollView becomeFirstResponder];
    _scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
    _scrollView.contentSize = CGSizeMake(KWidth, KHeight*4);
    [self.view addSubview:_scrollView];
    
    
    [self headImgview];
    [self houseMessage];
    [self brokerView];
    [self facilityView];
    [self plotDetail];
//    [self describeView];
    [self creatTaBar];
    [self loadData];
    [self loadPloatData];
    [self loadBrokerData];
    [self alertView];
    
}

//下拉刷新
- (void)headerRefresh {
    
    [self loadData];
    [self loadPloatData];
    [self loadBrokerData];
    
}

//获取小区详情
- (void)loadPloatData {
    
    
    NSString *url = [NSString stringWithFormat:@"%@xq/info",Main_Url];
    NSString *md5String = [NSString stringWithFormat:@"%@%@%@",self.sn,APPKEY_URL,url];
    md5String = [LCMD5Tool MD5ForLower32Bate:md5String];
    NSDictionary *param = @{
                            
                            @"sn":self.sn,
                            @"sign":md5String
                            
                            };
    
    //    [param setValue:md5String forKey:@"sign"];
    
    [AFHttpTool requestWihtUrl:url params:param success:^(id response) {
        
        
        if ([response[@"code"] isEqualToString:@"10000"]) {
            
            NSDictionary *dic = response[@"data"];
            dic = [Utils nullDic:dic];
            PlotDetail *model = [PlotDetail mj_objectWithKeyValues:dic];
            [self reloadPlatData:model];
        }
        
        
    } failure:^(NSError *err) {
        
        
    }];

}

//获取租房详情
- (void)loadData {
    
    NSString *url = [NSString stringWithFormat:@"%@fang/info",Main_Url];
    NSString *md5String = [NSString stringWithFormat:@"%@%@%@",self.sn,APPKEY_URL,url];
    md5String = [LCMD5Tool MD5ForLower32Bate:md5String];
    NSDictionary *param = @{
                            
                            @"sn":self.sn,
                            @"sign":md5String
                            
                            };
    
    //    [param setValue:md5String forKey:@"sign"];
    
    [AFHttpTool requestWihtUrl:url params:param success:^(id response) {
        
        
        if ([response[@"code"] isEqualToString:@"10000"]) {
            
            NSDictionary *dic = response[@"data"];
            dic = [Utils nullDic:dic];
            FangDetailModel *model = [FangDetailModel mj_objectWithKeyValues:dic];
            
            //整理配套设施数据
            NSString *subsidiary = model.subsidiary;
            subsidiary = [subsidiary stringByReplacingOccurrencesOfString:@"\""withString:@""];
            subsidiary = [subsidiary stringByReplacingOccurrencesOfString:@"["withString:@""];
            subsidiary = [subsidiary stringByReplacingOccurrencesOfString:@"]"withString:@""];
            NSArray  *array = [subsidiary componentsSeparatedByString:@","];
            model.subArray = array;
            [self reloadData:model];
            
        }
        
        
    } failure:^(NSError *err) {
        
        
        
    }];

}

- (void)loadBrokerData {
    
    NSString *url = [NSString stringWithFormat:@"%@agent/info",Main_Url];
    NSString *md5String = [NSString stringWithFormat:@"%@%@%@",self.sn,APPKEY_URL,url];
    md5String = [LCMD5Tool MD5ForLower32Bate:md5String];
    NSDictionary *param = @{
                            @"sn":self.sn,
                            @"sign":md5String
                            };
    
    //    [param setValue:md5String forKey:@"sign"];
    
    [AFHttpTool requestWihtUrl:url params:param success:^(id response) {
        
        [_scrollView.mj_header endRefreshing];
        if ([response[@"code"] isEqualToString:@"10000"]) {
            
            NSDictionary *dic = response[@"data"];
            dic = [Utils nullDic:dic];
            BrokerModel *model = [BrokerModel mj_objectWithKeyValues:dic];
            [self reloadBrokerData:model];
        }
        
        
    } failure:^(NSError *err) {
        
        [_scrollView.mj_header endRefreshing];
    }];

    
}

//经纪人数据填充
- (void)reloadBrokerData:(BrokerModel *)model {
    
    UIImageView *imgview = (UIImageView *)[_scrollView viewWithTag:130];
    UILabel *nameLabel = (UILabel *)[_scrollView viewWithTag:131];
    UILabel *nameLabel2 = (UILabel *)[_scrollView viewWithTag:132];
    UILabel *nameLabel3 = (UILabel *)[_scrollView viewWithTag:133];
    UILabel *nameLabel4 = (UILabel *)[_scrollView viewWithTag:134];
    UILabel *nameLabel5 = (UILabel *)[_scrollView viewWithTag:135];
    
    [imgview sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@"头像"]];
    if ([model.name isEqualToString:@""]) {
        model.name = @"暂无数据";
    }
    if ([model.company isEqualToString:@""]) {
        model.company = @"暂无数据";
    }if ([model.region isEqualToString:@""]) {
        model.region = @"暂无数据";
    }
    if ([model.deal_num isEqualToString:@""]) {
        model.deal_num = @"暂无数据";
    }
    if ([model.look_num isEqualToString:@""]) {
        model.look_num = @"暂无数据";
    }
    nameLabel.text = model.name;
    nameLabel2.text = model.company;
    nameLabel3.text = model.region;
    nameLabel4.text = model.deal_num;
    nameLabel5.text = model.look_num;
}

//小区详情填充数据
- (void)reloadPlatData:(PlotDetail *)plotModel {
    
    NSArray *dataArray = @[plotModel.name,plotModel.d_wuyefei,plotModel.d_niandai,plotModel.d_hushu,plotModel.d_lvhualv,plotModel.d_chewei, plotModel.d_rongjilv,plotModel.city,plotModel.address,plotModel.d_wuyegongsi,plotModel.d_kaifashang,plotModel.d_jieshao];
    for (int i=0; i<dataArray.count; i++) {
        
        UILabel *label = (UILabel *)[_scrollView viewWithTag:200+i];
        if ([dataArray[i] isEqualToString:@""]) {
            
            label.text = @"暂无数据";
        }else {
            
            label.text = dataArray[i];
        }
        
        
    }
}

//租房详情填充数据
- (void)reloadData:(FangDetailModel *)model {
    
    UILabel *titleLabel = (UILabel *)[_scrollView viewWithTag:100];
    UILabel *address = (UILabel *)[_scrollView viewWithTag:101];
    UILabel *number = (UILabel *)[_scrollView viewWithTag:102];
    UILabel *creattime = (UILabel *)[_scrollView viewWithTag:103];
    UILabel *label = (UILabel *)[_scrollView viewWithTag:104];
    UILabel *label2 = (UILabel *)[_scrollView viewWithTag:105];
    UILabel *label3 = (UILabel *)[_scrollView viewWithTag:106];
    UILabel *label4 = (UILabel *)[_scrollView viewWithTag:107];
    UILabel *label5 = (UILabel *)[_scrollView viewWithTag:108];
    UILabel *label6 = (UILabel *)[_scrollView viewWithTag:109];
    UILabel *label7 = (UILabel *)[_scrollView viewWithTag:110];

    NSArray *array = model.img;
    [_headView showScrollView:array];
    
    titleLabel.text = model.title;
    address.text = model.address;
    number.text = model.sn;
    creattime.text = model.createtime;
    label.text = [NSString stringWithFormat:@"%@元/月",model.rent];
    label2.text = [NSString stringWithFormat:@"%@室%@厅%@卫",model.bedroom,model.livingroom,model.washroom];
    label3.text = [NSString stringWithFormat:@"%@m²",model.square];
    label4.text = [NSString stringWithFormat:@"押%@/月付",model.deposit_method];
    label5.text = [NSString stringWithFormat:@"%@/共%@层/%@",model.floor,model.total_floor,model.orientation];
    NSString *str;
    if (model.createtime.length >4) {
      str  =  [model.createtime substringToIndex:4];
    }
    label6.text = [NSString stringWithFormat:@"%@建",str];
    label7.text = model.xq_name;
    
    //设施的数据
    for (NSString *str in model.subArray) {
        
        for (int i=0; i<facilityArray.count; i++) {
            
            if ([str isEqualToString:facilityArray[i]]) {
                
                UIImageView *imgView = (UIImageView *)[_scrollView viewWithTag:300+i];
                UILabel *label = (UILabel *)[_scrollView viewWithTag:400+i];
                imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@_01",str]];
                label.textColor = [Utils colorConvertFromString:@"#101010"];
            }
        }
    }
    
}

//房源图片和基本信息
- (void)headImgview{
    
    navgationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 64)];
    navgationView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:navgationView];
    
    NSArray *imgArray = @[@"loading.jpg",@"loading.jpg",@"loading.jpg",@"loading.jpg"];
    _headView = [[RVHeadView alloc] initWithFrame:CGRectMake(0, 0, KWidth, KWidth*346/750)];
    [_scrollView addSubview:_headView];
    [_headView showScrollView:imgArray];
    
    
    // 自定义导航栏左侧按钮
    UIButton * leftBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn2.frame = CGRectMake(-5, 0, 10, 15);
    [leftBtn2 setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [leftBtn2 addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem2 = [[UIBarButtonItem alloc] initWithCustomView:leftBtn2];
    self.navigationItem.leftBarButtonItem = leftItem2;
    
    // 自定义导航栏左侧按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(15, 15+20, 100,30);
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 10, 90)];
    [leftBtn setImage:[UIImage imageNamed:@"箭头左detiail"] forState:UIControlStateHighlighted];
    [leftBtn setImage:[UIImage imageNamed:@"箭头左detiail"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [navgationView addSubview:leftBtn];
    
    // 自定义导航栏左侧按钮
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(KWidth-60, 10+20, 60, 30);
    [rightBtn setImage:[UIImage imageNamed:@"消息detail"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(noticeAction) forControlEvents:UIControlEventTouchUpInside];
    [navgationView addSubview:rightBtn];
    
    Y = KWidth*346/750;
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, Y+15, KWidth-30, 40)];
    titleLabel.text = @"紧邻十五号地铁 家电齐全 双南向 采光好";
    titleLabel.tag = 100;
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont boldSystemFontOfSize:16];
    titleLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    [_scrollView addSubview:titleLabel];
    
    Y = Y+40+13+15;
    
    NSArray *headImgArray = @[@"位置-(1)-拷贝-2",@"合同编号",@"时间"];
    NSArray *introduceArray = @[@"位置:",@"编号:",@"更新时间:"];
    NSArray *titleArray = @[@"深圳市南山区科技中三路一号",@"10008966",@"2015年6月6号"];
    
    CGFloat margin = 10;
    CGFloat hight = 15;
    for (int i=0; i<headImgArray.count; i++) {
        
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(15+2, Y+(hight+margin)*i+2, hight-4, hight-2)];
        imgView.image = [UIImage imageNamed:headImgArray[i]];
        [_scrollView addSubview:imgView];
        
        
        UILabel *introduce = [[UILabel alloc] init];
        introduce.text = introduceArray[i];
        introduce.font = [UIFont systemFontOfSize:12];
        introduce.textColor = [Utils colorConvertFromString:@"#101010"];
        introduce.textAlignment = NSTextAlignmentCenter;
        CGSize size = [introduceArray[i] boundingRectWithSize:CGSizeMake(KWidth, hight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:introduce.font} context:nil].size;
        introduce.frame = CGRectMake(35, Y+(hight+margin)*i, size.width, hight);
        
        [_scrollView addSubview:introduce];
        
        UILabel *titleLabel2 = [[UILabel alloc] init];
        titleLabel2.text = titleArray[i];
        titleLabel2.tag = 101+i;
        titleLabel2.font = [UIFont systemFontOfSize:12];
        titleLabel2.textColor = [Utils colorConvertFromString:@"#101010"];
        titleLabel2.textAlignment = NSTextAlignmentLeft;
//        CGSize size2 = [titleArray[i] boundingRectWithSize:CGSizeMake(KWidth, hight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titleLabel.font} context:nil].size;
        titleLabel2.frame = CGRectMake(40+size.width, Y+(hight+margin)*i, KWidth-size.width-35, hight);
        
        [_scrollView addSubview:titleLabel2];
    }
    
    Y = Y+hight*3+margin*2;
    
    //分割线
    CALayer *headLayer = [CALayer layer];
    headLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    headLayer.frame = CGRectMake(15 ,Y+15, KWidth-30, 1);
    [_scrollView.layer addSublayer:headLayer];
    

}

//房源信息
- (void)houseMessage {
    
    Y = Y+30;
    NSArray *messageArray = @[@"房租(月付)",@"房源户型",@"其他信息"];
    NSArray *contentArray = @[@"6500元/月",@"2室一厅一卫",@"68m²|精装"];
    NSArray *introArray = @[@"押一/月付",@"高层/共36层/朝南",@"2000年建"];
    CGFloat width = (KWidth-30)/3;
    CGFloat hight = 20;
    CGFloat margin = 10;
    for (int i=0; i<messageArray.count; i++) {
        
        UILabel *messLabel = [[UILabel alloc] init];
        messLabel.text = messageArray[i];
        messLabel.font = [UIFont systemFontOfSize:12];
        messLabel.textColor = [Utils colorConvertFromString:@"#666666"];
        messLabel.textAlignment = NSTextAlignmentLeft;
        messLabel.frame = CGRectMake(30+width*i, Y+(hight+margin)*0, width, hight);
        [_scrollView addSubview:messLabel];
        
        
        UILabel *contentLabel = [[UILabel alloc] init];
        contentLabel.text = contentArray[i];
        contentLabel.tag = 104+i;
        contentLabel.font = [UIFont boldSystemFontOfSize:14];
        contentLabel.textColor = [Utils colorConvertFromString:@"#333333"];
        if (i==0) {
            
            contentLabel.textColor = [Utils colorConvertFromString:@"#e52323"];
        }
        contentLabel.textAlignment = NSTextAlignmentLeft;
        contentLabel.frame = CGRectMake(30+width*i, Y+(hight+margin), width, hight);
        NSRange range = [contentLabel.text rangeOfString:@"0.00"];
        [self setTextColor:contentLabel FontNumber:[UIFont systemFontOfSize:16] AndRange:range AndColor:[Utils colorConvertFromString:@"#e52323"]];
//        [self setRichNumberWithLabel:contentLabel Color:[Utils colorConvertFromString:@"#e52323"] FontSize:15];
        [_scrollView addSubview:contentLabel];
        
        
        UILabel *introLabel = [[UILabel alloc] init];
        introLabel.text = introArray[i];
        introLabel.tag = 107+i;
        introLabel.font = [UIFont systemFontOfSize:12];
        introLabel.textColor = [Utils colorConvertFromString:@"#333333"];
        introLabel.textAlignment = NSTextAlignmentLeft;
        introLabel.frame = CGRectMake(30+width*i, Y+(hight+margin)*2, width, hight);
        [_scrollView addSubview:introLabel];

    }
    
    Y = Y+hight*3+margin*2+15;
    //分割线
    CALayer *headLayer = [CALayer layer];
    headLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    headLayer.frame = CGRectMake(15 ,Y, KWidth-30, 1);
    [_scrollView.layer addSublayer:headLayer];

    //区域
    UILabel *areaLael = [[UILabel alloc] init];
    areaLael.text = @"所在区域:";
    areaLael.font = [UIFont systemFontOfSize:12];
    areaLael.textColor = [Utils colorConvertFromString:@"#333333"];
    areaLael.textAlignment = NSTextAlignmentCenter;
    CGSize size = [@"所在区域: " boundingRectWithSize:CGSizeMake(KWidth, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:areaLael.font} context:nil].size;
    areaLael.frame = CGRectMake(30, Y+15, size.width, 15);
    [_scrollView addSubview:areaLael];
    
    //看周边配套
    UILabel *matingLael = [[UILabel alloc] init];
    matingLael.text = @"周边配套 >";
    matingLael.font = [UIFont systemFontOfSize:12];
    matingLael.textColor = [Utils colorConvertFromString:@"#333333"];
    matingLael.textAlignment = NSTextAlignmentLeft;
    CGSize size2 = [@"周边配套 >  " boundingRectWithSize:CGSizeMake(KWidth, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:matingLael.font} context:nil].size;
    matingLael.frame = CGRectMake(KWidth-size2.width, Y+20, size2.width, 20);
    
    //添加手势
    UITapGestureRecognizer * PrivateLetterTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(matingtapAvatarView)];
    PrivateLetterTap.numberOfTouchesRequired = 1; //手指数
    PrivateLetterTap.numberOfTapsRequired = 1; //tap次数
    [matingLael addGestureRecognizer:PrivateLetterTap];

    [_scrollView addSubview:matingLael];
    
    //具体小区
    UILabel *areaCentLael = [[UILabel alloc] init];
    areaCentLael.text = @"南山区-科技园-汇林小区";
    areaCentLael.tag = 110;
    areaCentLael.font = [UIFont systemFontOfSize:12];
    areaCentLael.textColor = [Utils colorConvertFromString:@"#333333"];
    areaCentLael.textAlignment = NSTextAlignmentLeft;
    areaCentLael.frame = CGRectMake(30+size.width+10, Y+15, KWidth-30-size.width-size2.width-20, 15);
    [_scrollView addSubview:areaCentLael];
    
    //共多少套
    UILabel *numLael = [[UILabel alloc] init];
    numLael.text = @"(共16套)";
    numLael.tag = 111;
    numLael.font = [UIFont systemFontOfSize:12];
    numLael.textColor = [Utils colorConvertFromString:@"#333333"];
    numLael.textAlignment = NSTextAlignmentLeft;
    numLael.frame = CGRectMake(30+size.width+10, Y+35, KWidth-30-size.width-size2.width-20, 15);
    [_scrollView addSubview:numLael];
    
    Y = Y+55;
    //分割线
    CALayer *areaLayer = [CALayer layer];
    areaLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    areaLayer.frame = CGRectMake(15 ,Y, KWidth-30, 1);
    [_scrollView.layer addSublayer:areaLayer];
    
    //优势
    UILabel *advantageLael = [[UILabel alloc] init];
    advantageLael.text = @"优    势:";
    advantageLael.font = [UIFont systemFontOfSize:12];
    advantageLael.textColor = [Utils colorConvertFromString:@"#333333"];
    advantageLael.textAlignment = NSTextAlignmentCenter;
    CGSize size3 = [@"优    势:" boundingRectWithSize:CGSizeMake(KWidth, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:advantageLael.font} context:nil].size;
    advantageLael.frame = CGRectMake(30, Y+15, size3.width, 15);
    [_scrollView addSubview:advantageLael];
    
    NSArray *advantageArray = @[@"学校附近",@"地铁口",@"购物方便"];
    NSArray *colorArray = @[@"#e2a438",@"#e8376d",@"#2defba"];
    CGFloat width2 = size3.width+10;
    for (int i=0; i<advantageArray.count; i++) {
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(35+width2*i+10*i+width2+10, Y+15, size3.width+10, 15)];
        label.font = [UIFont systemFontOfSize:10];
        label.text = advantageArray[i];
        label.textAlignment = NSTextAlignmentCenter;
        label.layer.borderWidth = 1;
        label.layer.borderColor = [Utils colorConvertFromString:colorArray[i]].CGColor;
        label.layer.masksToBounds = YES;
        label.layer.cornerRadius = 1;
        label.textColor = [Utils colorConvertFromString:colorArray[i]];
        [_scrollView addSubview:label];
    }
    
    Y = Y+40;
    //分割线
    CALayer *advantageLayer = [CALayer layer];
    advantageLayer.backgroundColor = [[Utils colorConvertFromString:@"#efefef"] CGColor];
    advantageLayer.frame = CGRectMake(0 ,Y, KWidth, 10);
    [_scrollView.layer addSublayer:advantageLayer];
    
    Y = Y + 4;
    
}

//经纪人信息
- (void)brokerView {
    
    
    UIImageView *sectionView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15+Y, 15, 15)];
    sectionView.image = [UIImage imageNamed:@"经纪人管理_icon"];
    [_scrollView addSubview:sectionView];
    
    //经纪人
    UILabel *sectionLael = [[UILabel alloc] initWithFrame:CGRectMake(35, 15+Y, KWidth-30, 15)];
    
    sectionLael.text = @"经纪人";
    sectionLael.font = [UIFont systemFontOfSize:16];
    sectionLael.textColor = [Utils colorConvertFromString:@"#333333"];
    sectionLael.textAlignment = NSTextAlignmentLeft;
    [_scrollView addSubview:sectionLael];

    
    //分割线
    CALayer *sectionLayer = [CALayer layer];
    sectionLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    sectionLayer.frame = CGRectMake(15 ,Y+40, KWidth-30, 1);
    [_scrollView.layer addSublayer:sectionLayer];

    Y = Y + 40;
    
    CGFloat hight2 = 50;
    
    UIImageView *brokerView = [[UIImageView alloc] initWithFrame:CGRectMake(27, 20+Y, hight2, hight2)];
    brokerView.tag = 130;
    brokerView.image = [UIImage imageNamed:@"头像"];
    [_scrollView addSubview:brokerView];
    
    //名字
    UILabel *nameLael = [[UILabel alloc] init];
    nameLael.text = @"暂无数据";
    nameLael.tag = 131;
    nameLael.font = [UIFont boldSystemFontOfSize:15];
    nameLael.textColor = [Utils colorConvertFromString:@"#333333"];
    nameLael.textAlignment = NSTextAlignmentLeft;
    
    CGSize size = [@"暂无数据" boundingRectWithSize:CGSizeMake(KWidth/2, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:nameLael.font} context:nil].size;
    nameLael.frame = CGRectMake(27+hight2+24, Y+15, size.width, 20);
    [_scrollView addSubview:nameLael];
    
    UIImageView *attestationView = [[UIImageView alloc] initWithFrame:CGRectMake(27+hight2+24+size.width+10, 17+Y, 13 , 15)];
    attestationView.image = [UIImage imageNamed:@"认证-(2)-拷贝-2"];
    [_scrollView addSubview:attestationView];
    
    //名字
    UILabel *attestationLael = [[UILabel alloc] init];
    attestationLael.text = @"已认证 ";
    attestationLael.font = [UIFont boldSystemFontOfSize:8];
    attestationLael.textColor = [Utils colorConvertFromString:@"#70b985"];
    attestationLael.textAlignment = NSTextAlignmentCenter;
    [_scrollView addSubview:attestationLael];
    CGSize size2 = [@"已认证 " boundingRectWithSize:CGSizeMake(KWidth, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:attestationLael.font} context:nil].size;
    [attestationLael mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(attestationView.mas_right).with.offset(5);
        make.centerY.equalTo(nameLael.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(size2.width, 20));
    }];
    
    Starview *starView = [[Starview alloc] initWithFrame:CGRectMake(0, 0, 75, 12)];
    starView.index = 4;
    [_scrollView addSubview:starView];
    
    [starView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(attestationLael.mas_centerY);
        make.left.equalTo(attestationLael.mas_right).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(75, 12));
    }];
    
    Y = Y+15+15+10;
    
    NSArray *headImgArray = @[@"小区 detail",@"地点-拷贝"];
    NSArray *introduceArray = @[@"所属中介:",@"主要区域:"];
    NSArray *titleArray = @[@"北京华飞房屋租赁有限公司",@"北京-东城区-安定门"];
    
    CGFloat margin = 8;
    CGFloat hight = 10;
    for (int i=0; i<headImgArray.count; i++) {
        
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(27+hight2+24, Y+(hight+margin)*i+2, hight, hight)];
        imgView.image = [UIImage imageNamed:headImgArray[i]];
        [_scrollView addSubview:imgView];
        
        
        UILabel *introduce = [[UILabel alloc] init];
        introduce.text = introduceArray[i];
        introduce.font = [UIFont systemFontOfSize:12];
        introduce.textColor = [Utils colorConvertFromString:@"#101010"];
        introduce.textAlignment = NSTextAlignmentCenter;
        CGSize size = [introduceArray[i] boundingRectWithSize:CGSizeMake(KWidth, hight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:introduce.font} context:nil].size;
        introduce.frame = CGRectMake(27+hight2+24+13, Y+(hight+margin)*i, size.width, hight);
        
        [_scrollView addSubview:introduce];
        
        UILabel *titleLabel2 = [[UILabel alloc] init];
        titleLabel2.text = titleArray[i];
        titleLabel2.tag = 132+i;
        titleLabel2.font = [UIFont systemFontOfSize:12];
        titleLabel2.textColor = [Utils colorConvertFromString:@"#101010"];
        titleLabel2.textAlignment = NSTextAlignmentLeft;
        CGSize size2 = [titleArray[i] boundingRectWithSize:CGSizeMake(KWidth, hight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titleLabel2.font} context:nil].size;
        titleLabel2.frame = CGRectMake(27+hight2+24+15+size.width, Y+(hight+margin)*i, size2.width, hight);
        
        [_scrollView addSubview:titleLabel2];
    }
    
    Y = Y + 20+10;
    //分割线
    CALayer *headLayer = [CALayer layer];
    headLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    headLayer.frame = CGRectMake(15 ,Y+15, KWidth-30, 1);
    [_scrollView.layer addSublayer:headLayer];
    
    Y = Y + 15;
    
    NSArray *titleArray2 = @[@"30天内成交(套)",@"30天内看房(次)"];
    NSArray *numArray = @[@"3",@"2138"];
    for (int i=0; i<titleArray.count; i++) {
        
        UILabel *numLabel = [[UILabel alloc] initWithFrame:CGRectMake((KWidth-1)/2*i, 15+Y, (KWidth-1)/2, 20)];
        numLabel.text = numArray[i];
        numLabel.tag = 134+i;
        numLabel.font = [UIFont boldSystemFontOfSize:16];
        numLabel.textColor = [Utils colorConvertFromString:@"#70b985"];
        numLabel.textAlignment = NSTextAlignmentCenter;
        [_scrollView addSubview:numLabel];
        
        if (i == 0) {
            //分割线
            CALayer *midleLayer = [CALayer layer];
            midleLayer.backgroundColor = [[Utils colorConvertFromString:@"#efefef"] CGColor];
            midleLayer.frame = CGRectMake((KWidth-1)/2 ,Y+10,1 , 45);
            [_scrollView.layer addSublayer:midleLayer];
        }
        
        UILabel *titileLabel = [[UILabel alloc] initWithFrame:CGRectMake((KWidth-1)/2*i, 40+Y, (KWidth-1)/2, 20)];
        titileLabel.text = titleArray2[i];
        titileLabel.font = [UIFont systemFontOfSize:10];
        titileLabel.textColor = [Utils colorConvertFromString:@"#666666"];
        titileLabel.textAlignment = NSTextAlignmentCenter;
        [_scrollView addSubview:titileLabel];
        
    }

    Y = Y + 40 +20 + 10;
    //分割线
    CALayer *advantageLayer = [CALayer layer];
    advantageLayer.backgroundColor = [[Utils colorConvertFromString:@"#efefef"] CGColor];
    advantageLayer.frame = CGRectMake(0 ,Y, KWidth, 10);
    [_scrollView.layer addSublayer:advantageLayer];
    
    
    Y = Y + 10;

}

//配套设施
- (void)facilityView {
    
    UIImageView *sectionView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15+Y, 15, 15)];
    sectionView.image = [UIImage imageNamed:@"设施"];
    [_scrollView addSubview:sectionView];
    
    //经纪人
    UILabel *sectionLael = [[UILabel alloc] initWithFrame:CGRectMake(35, 15+Y, KWidth-30, 15)];
    sectionLael.text = @"配套设施";
    sectionLael.font = [UIFont systemFontOfSize:16];
    sectionLael.textColor = [Utils colorConvertFromString:@"#333333"];
    sectionLael.textAlignment = NSTextAlignmentLeft;
    [_scrollView addSubview:sectionLael];
    
    //分割线
    CALayer *sectionLayer = [CALayer layer];
    sectionLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    sectionLayer.frame = CGRectMake(15 ,Y+40, KWidth-30, 1);
    [_scrollView.layer addSublayer:sectionLayer];
    
    Y = Y + 40;

    facilityArray = @[@"床",@"沙发",@"冰箱",@"空调",@"电视机",@"热水器",@"洗衣机",@"微波炉",@"衣柜",@"宽带"];
    
    CGFloat width = 32;
    CGFloat hight = 32+15+2;
    CGFloat margin = (KWidth-32*5)/6;
    CGFloat marginH = 15;
    CGFloat labelW = (KWidth-margin)/5;
    for (int i=0; i<facilityArray.count; i++) {
        
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(width*(i%5)+margin*(i%5+1), hight*(i/5)+marginH*(i/5+1)+Y, width, width)];
        imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@_02",facilityArray[i]]];
        imgView.tag = 300+i;
        [_scrollView addSubview:imgView];
        
        

        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(margin/2+labelW*(i%5),hight*(i/5)+marginH*(i/5+1)+Y+37, labelW, 12)];
        label.text = facilityArray[i];
        label.tag = 400+i;
        label.font = [UIFont systemFontOfSize:12];
        label.textColor = [Utils colorConvertFromString:@"#bababa"];
        label.textAlignment = NSTextAlignmentCenter;
        [_scrollView addSubview:label];
        
        
    }
    
    Y = Y +hight*2+45;
    
    //分割线
    CALayer *advantageLayer = [CALayer layer];
    advantageLayer.backgroundColor = [[Utils colorConvertFromString:@"#efefef"] CGColor];
    advantageLayer.frame = CGRectMake(0 ,Y, KWidth, 10);
    [_scrollView.layer addSublayer:advantageLayer];
    
    Y = Y + 10;
}

//小区详情
- (void)plotDetail {
    
    UIImageView *sectionView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15+Y, 15, 15)];
    sectionView.image = [UIImage imageNamed:@"小区"];
    [_scrollView addSubview:sectionView];
    
    //经纪人
    UILabel *sectionLael = [[UILabel alloc] initWithFrame:CGRectMake(35, 15+Y, KWidth-30, 15)];
    sectionLael.text = @"小区详情";
    sectionLael.font = [UIFont systemFontOfSize:16];
    sectionLael.textColor = [Utils colorConvertFromString:@"#333333"];
    sectionLael.textAlignment = NSTextAlignmentLeft;
    [_scrollView addSubview:sectionLael];
    
    
    //分割线
    CALayer *sectionLayer = [CALayer layer];
    sectionLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    sectionLayer.frame = CGRectMake(15 ,Y+40, KWidth-30, 1);
    [_scrollView.layer addSublayer:sectionLayer];
    
    Y = Y +40;
    
    NSArray *titleArray = @[@"小区名称:",@"物业费:",@"建造年代:",@"总户数:",@"绿化率:",@"停车位:",@"容积率:",@"所在版块:",@"小区地址:",@"物业公司:",@"开发商:",@"小区介绍:"];
    NSArray *contentArray = @[@"芳华香榭",@"2.5/平米/每月",@"2012年",@"6000户",@"3.6%",@"700",@"3.6",@"南山区科技园",@"中意三号",@"深圳天明物业管理公司",@"深圳市发和房地产开发公司",@"小区采用底层,小高层,高层结合的布局.高低错落有致,所以栋号房间皆为南北朝向,楼间距适度"];
    
    CGFloat hight = 45;
    for (int i=0; i<titleArray.count; i++) {
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = titleArray[i];
        titleLabel.textAlignment = NSTextAlignmentLeft;
        titleLabel.font = [UIFont systemFontOfSize:13];
        titleLabel.textColor = [Utils colorConvertFromString:@"#101010"];
        [_scrollView addSubview:titleLabel];
        CGSize size = [titleArray[i] boundingRectWithSize:CGSizeMake(KWidth/2, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titleLabel.font} context:nil].size;
        
        UILabel *contentLabel = [[UILabel alloc] init];
        contentLabel.text = contentArray[i];
        contentLabel.tag = 200+i;
        contentLabel.textAlignment = NSTextAlignmentLeft;
        contentLabel.font = [UIFont systemFontOfSize:13];
        contentLabel.textColor = [Utils colorConvertFromString:@"#101010"];
        [_scrollView addSubview:contentLabel];
        
       
        
        //分割线
        CALayer *sectionLayer = [CALayer layer];
        sectionLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
        [_scrollView.layer addSublayer:sectionLayer];
        
        if (i < 6) {
            
            titleLabel.frame = CGRectMake(22.5+(KWidth-45)/2*(i%2), hight*(i/2)+15+Y, (KWidth-45)/2, 15);
            contentLabel.frame = CGRectMake((KWidth-45)/2*(i%2)+size.width+22.5+5, hight*(i/2)+15+Y, (KWidth-45)/2, 15);
            sectionLayer.frame = CGRectMake(15 ,hight*(i/2+1)+Y, KWidth-30, 1);

        }else {
            
             titleLabel.frame = CGRectMake(22.5, hight*(i-6)+hight*3+15+Y, size.width, 15);
             contentLabel.frame = CGRectMake(22.5+size.width+10, hight*(i-6)+hight*3+15+Y,KWidth-size.width-55, 15);
            sectionLayer.frame = CGRectMake(15 ,hight*(i-6+1)+hight*3+Y, KWidth-30, 1);
            
        }
        
        if (i == titleArray.count -1) {
            
            contentLabel.numberOfLines = 0;
            contentLabel.font = [UIFont systemFontOfSize:11];
            contentLabel.frame = CGRectMake(22.5+size.width+10, hight*(i-6)+hight*3+15+Y,KWidth-size.width-55, 30);
            sectionLayer.frame = CGRectMake(15 ,hight*(i-6+1)+hight*3+Y+15, KWidth-30, 1);
        }
    }
    
    Y = Y+hight*8+59;
    //分割线
    CALayer *advantageLayer = [CALayer layer];
    advantageLayer.backgroundColor = [[Utils colorConvertFromString:@"#efefef"] CGColor];
    advantageLayer.frame = CGRectMake(0 ,Y, KWidth, 10);
    [_scrollView.layer addSublayer:advantageLayer];
    
    Y = Y + 10;
    _scrollView.contentSize = CGSizeMake(KWidth , Y-49);
}

//小区描述
- (void)describeView {
    
    UIImageView *sectionView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15+Y, 15, 15)];
    sectionView.image = [UIImage imageNamed:@"项目描述"];
    [_scrollView addSubview:sectionView];
    
    //经纪人
    UILabel *sectionLael = [[UILabel alloc] initWithFrame:CGRectMake(35, 15+Y, KWidth-30, 15)];
    sectionLael.text = @"项目描述";
    sectionLael.font = [UIFont systemFontOfSize:16];
    sectionLael.textColor = [Utils colorConvertFromString:@"#333333"];
    sectionLael.textAlignment = NSTextAlignmentLeft;
    [_scrollView addSubview:sectionLael];
    
    
    //分割线
    CALayer *sectionLayer = [CALayer layer];
    sectionLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    sectionLayer.frame = CGRectMake(15 ,Y+40, KWidth-30, 1);
    [_scrollView.layer addSublayer:sectionLayer];
    
    Y = Y+45;
    
    NSArray *titleArray = @[@"装修描述:",@"交通出行:",@"周边配套:",@"户型介绍",@"房源优势"];
    CGFloat hight = 60;
    for (int i=0; i<titleArray.count; i++) {
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = titleArray[i];
        titleLabel.textAlignment = NSTextAlignmentLeft;
        titleLabel.font = [UIFont systemFontOfSize:13];
        titleLabel.textColor = [Utils colorConvertFromString:@"#101010"];
        [_scrollView addSubview:titleLabel];
        CGSize size = [titleArray[i] boundingRectWithSize:CGSizeMake(KWidth/2, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titleLabel.font} context:nil].size;
        titleLabel.frame = CGRectMake(22.5, 15+hight*i+Y, size.width, 15);
        
        UILabel *contentLabel = [[UILabel alloc] init];
        contentLabel.text = @"小区采用底层,小高层,高层结合的布局.高低错落有致,所以栋号房间皆为南北朝向,楼间距适度";
        contentLabel.textAlignment = NSTextAlignmentLeft;
        contentLabel.font = [UIFont systemFontOfSize:11];
        contentLabel.textColor = [Utils colorConvertFromString:@"#101010"];
        contentLabel.numberOfLines = 0;
        contentLabel.frame = CGRectMake(size.width+27.5, hight*i+15+Y, KWidth-45-size.width, 30);
        [_scrollView addSubview:contentLabel];
        
        CALayer *sectionLayer = [CALayer layer];
        sectionLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
        sectionLayer.frame = CGRectMake(15 ,Y+hight*i+59, KWidth-30, 1);
        [_scrollView.layer addSublayer:sectionLayer];

    }
    
    Y = Y+hight*titleArray.count-1;
    //分割线
    CALayer *advantageLayer = [CALayer layer];
    advantageLayer.backgroundColor = [[Utils colorConvertFromString:@"#efefef"] CGColor];
    advantageLayer.frame = CGRectMake(0 ,Y, KWidth, 10);
    [_scrollView.layer addSublayer:advantageLayer];
   
    
}

- (void)creatTaBar {
    
    UIView *tabView = [[UIView alloc] initWithFrame:CGRectMake(0,KHeight-45, KWidth, 45)];
    CALayer *MlineLayer14 = [CALayer layer];
    MlineLayer14.backgroundColor = [[Utils colorConvertFromString:@"#F2F2F2"] CGColor];
    MlineLayer14.frame = CGRectMake(0 ,1, KWidth, 1);
    [tabView.layer addSublayer:MlineLayer14];
    
    [self.view addSubview:tabView];
    NSArray *imgArray = @[@"收-藏",@"添加-(1)",@"分享"];
    NSArray *titleArray = @[@"收藏",@"添加",@"分享"];
    CGFloat width = 55;
    for (int i=0; i<imgArray.count; i++) {
        
        
        UIControl *control = [[UIControl alloc] initWithFrame:CGRectMake((width+1)*i,1,55,44)];
        control.tag = 1000+i;
        control.userInteractionEnabled = YES;
        
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake((54-12)/2,8,15,15)];
        imgView.image = [UIImage imageNamed:imgArray [i]];
        [control addSubview:imgView];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 23, width, 20)];
        label.text = titleArray[i];
        label.textColor = [Utils colorConvertFromString:@"#fc7f33"];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:12];
        [control addSubview:label];
        
        [control addTarget:self action:@selector(tabSelectAction:) forControlEvents:UIControlEventTouchUpInside];
        [tabView addSubview:control];
        
        //分割线
        if (i<2) {
            
            CALayer *MlineLayer13 = [CALayer layer];
            MlineLayer13.backgroundColor = [[Utils colorConvertFromString:@"#f2f2f2"] CGColor];
            MlineLayer13.frame = CGRectMake((width+1)*(i+1) ,0, 1, 40);
            [tabView.layer addSublayer:MlineLayer13];
        }
    }
    
    UIButton *inquiryBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    inquiryBtn.frame = CGRectMake(width*3, 1 ,KWidth-width*3, 44);
    [inquiryBtn setBackgroundColor:[Utils colorConvertFromString:@"#fc7f33"]];
    [inquiryBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [inquiryBtn setTitle:@"咨询经纪人" forState:UIControlStateNormal];
    inquiryBtn.layer.masksToBounds = YES;
    [inquiryBtn addTarget:self action:@selector(inquiryAction) forControlEvents:UIControlEventTouchUpInside];
    [tabView addSubview:inquiryBtn];
    
    //    CGFloat width = (KWidth - 210*Main_Scale)/3;
    //    CGFloat heigh =
    Y = Y+45;
    
}

//创建弹窗视图
- (void)alertView {
    
    markView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWidth, KHeight)];
    markView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
    
    markView.userInteractionEnabled = YES;
//    [markView becomeFirstResponder];
    [self.view insertSubview:markView belowSubview:self.view];
    //添加手势
    UITapGestureRecognizer * PrivateLetterTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAvatarView)];
    PrivateLetterTap.delegate = self;
    PrivateLetterTap.numberOfTouchesRequired = 1; //手指数
    PrivateLetterTap.numberOfTapsRequired = 1; //tap次数
    [markView addGestureRecognizer:PrivateLetterTap];
    
    
    //预约弹窗
    CGFloat width = 240;
    CGFloat hight = 180;
    subscribeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, hight)];
    subscribeView.center = self.view.center;
    subscribeView.backgroundColor = [UIColor whiteColor];
    subscribeView.layer.masksToBounds = YES;
    subscribeView.layer.cornerRadius = 10;
//    subscribeView.hidden = YES;
    markView.hidden = YES;
    [markView addSubview:subscribeView];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,20,width, 20)];
    titleLabel.text = @"请填写预约人信息";
    titleLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    titleLabel.font = [UIFont boldSystemFontOfSize:15];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [subscribeView addSubview:titleLabel];
    
    NSArray *titleArray = @[@"联系人:",@"手机号:"];
    NSArray *parArray = @[@"请输入联系人姓名",@"请输入联系人手机号码"];
    for (int i=0; i<titleArray.count; i++) {
        
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:12];
        label.textColor = [Utils colorConvertFromString:@"#101010"];
        CGSize size = [titleArray[1] boundingRectWithSize:CGSizeMake(KWidth,20 ) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:nil].size;
        label.frame = CGRectMake(20, 60+30*i, size.width, 20);
        label.text = titleArray[i];
        [subscribeView addSubview:label];
        
        UITextField *numText = [[UITextField alloc] initWithFrame:CGRectMake(35+size.width,60+30*i, width-40-size.width-15, 20)];
        numText.placeholder = parArray[i];
//        numText.delegate = self;
        numText.tag = 190+i;
        numText.font = [UIFont systemFontOfSize:12];
        [subscribeView addSubview:numText];
        
        CALayer *lineLayer2 = [CALayer layer];
        lineLayer2.backgroundColor = [[UIColor colorWithRed:217/255.0 green:217/255.0 blue:217/255.0 alpha:1] CGColor];
        lineLayer2.frame = CGRectMake(35+size.width,60+30*i+21,width-40-size.width-15, 1);
        [subscribeView.layer addSublayer:lineLayer2];
    }
    
    CALayer *lineLayer2 = [CALayer layer];
    lineLayer2.backgroundColor = [[UIColor colorWithRed:217/255.0 green:217/255.0 blue:217/255.0 alpha:1] CGColor];
    lineLayer2.frame = CGRectMake(0,60+30*2+20,width, 1);
    [subscribeView.layer addSublayer:lineLayer2];
    
    CALayer *mlineLayer2 = [CALayer layer];
    mlineLayer2.backgroundColor = [[UIColor colorWithRed:217/255.0 green:217/255.0 blue:217/255.0 alpha:1] CGColor];
    mlineLayer2.frame = CGRectMake((width-1)/2,60+30*2+20,1,40);
    [subscribeView.layer addSublayer:mlineLayer2];
    
    UIButton *sureButton = [UIButton buttonWithType:UIButtonTypeSystem];
    sureButton.frame = CGRectMake(0, 140, (width-1)/2, 40);
    [sureButton addTarget:self action:@selector(subscribeSureAction) forControlEvents:UIControlEventTouchUpInside];
    [sureButton setTitle:@"提交" forState:UIControlStateNormal];
    
    [subscribeView addSubview:sureButton];
    
    UIButton *canceButton = [UIButton buttonWithType:UIButtonTypeSystem];
    canceButton.frame = CGRectMake((width-1)/2, 140, (width-1)/2, 40);
    [canceButton setTitle:@"取消" forState:UIControlStateNormal];
    [canceButton addTarget:self action:@selector(subscribeCanceAction) forControlEvents:UIControlEventTouchUpInside];
    [subscribeView addSubview:canceButton];


    hight = 240;
    successView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, hight)];
    successView.center = self.view.center;
    successView.hidden = YES;
    successView.backgroundColor = [UIColor whiteColor];
    successView.layer.masksToBounds = YES;
    successView.layer.cornerRadius = 10;
    [markView addSubview:successView];
    
    UIImageView *succImgView = [[UIImageView alloc] initWithFrame:CGRectMake((width-60)/2, 20, 60, 60)];
    succImgView.image = [UIImage imageNamed:@"img_complete"];
    [successView addSubview:succImgView];
    
    UILabel *prolabel = [[UILabel alloc] init];
    prolabel.font = [UIFont systemFontOfSize:18];
    prolabel.textAlignment = NSTextAlignmentCenter;
    prolabel.textColor = [Utils colorConvertFromString:@"#101010"];
    prolabel.frame = CGRectMake(0,90, width, 20);
    prolabel.text = @"提交成功";
    [successView addSubview:prolabel];

    
    NSArray *succArray = @[@"您的预约已成功提交,请耐心等待房主",@"与您联系,如需帮助,请您拨打租客网",@"免费服务热线:4006-222222"];
    for (int i=0; i<succArray.count; i++) {
        
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:12];
        label.textColor = [Utils colorConvertFromString:@"#333333"];
        label.frame = CGRectMake(0, 120+17*i, width, 12);
        label.text = succArray[i];
        label.textAlignment = NSTextAlignmentCenter;
        [successView addSubview:label];
    }
    CALayer *succlineLayer2 = [CALayer layer];
    succlineLayer2.backgroundColor = [[UIColor colorWithRed:217/255.0 green:217/255.0 blue:217/255.0 alpha:1] CGColor];
    succlineLayer2.frame = CGRectMake(0,200,width,1);
    [successView.layer addSublayer:succlineLayer2];

    UIButton *suceeButton = [UIButton buttonWithType:UIButtonTypeSystem];
    suceeButton.frame = CGRectMake(0, 200, width, 40);
    [suceeButton setTitle:@"确定" forState:UIControlStateNormal];
    [suceeButton addTarget:self action:@selector(subscribesuccAction) forControlEvents:UIControlEventTouchUpInside];
    [successView addSubview:suceeButton];
    
    hight = 200;
    UIView *warnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, hight)];
    warnView.center = self.view.center;
    warnView.hidden = YES;
    warnView.backgroundColor = [UIColor whiteColor];
    warnView.layer.masksToBounds = YES;
    warnView.layer.cornerRadius = 10;
    [markView addSubview:warnView];
    
    UIImageView *warmImgView = [[UIImageView alloc] initWithFrame:CGRectMake((width-60)/2, 20, 60, 60)];
    warmImgView.image = [UIImage imageNamed:@"警告"];
    [warnView addSubview:warmImgView];
    
    NSArray *warmArray = @[@"您已经对该房源进行看房预约,请耐心等",@"待房主的联系,请勿重复提交预约"];
    for (int i=0; i<warmArray.count; i++) {
        
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:12];
        label.textColor = [Utils colorConvertFromString:@"#333333"];
        label.frame = CGRectMake(0, 100+17*i, width, 12);
        label.text = warmArray[i];
        label.textAlignment = NSTextAlignmentCenter;
        [warnView addSubview:label];
    }
    
    CALayer *warmlineLayer2 = [CALayer layer];
    warmlineLayer2.backgroundColor = [[UIColor colorWithRed:217/255.0 green:217/255.0 blue:217/255.0 alpha:1] CGColor];
    warmlineLayer2.frame = CGRectMake(0,160,width,1);
    [warnView.layer addSublayer:warmlineLayer2];
    
    UIButton *warnButton = [UIButton buttonWithType:UIButtonTypeSystem];
    warnButton.frame = CGRectMake(0, 160, width, 40);
    [warnButton setTitle:@"确定" forState:UIControlStateNormal];
    [warnButton addTarget:self action:@selector(subscribesuccAction) forControlEvents:UIControlEventTouchUpInside];
    [warnView addSubview:warnButton];


}

- (void)subscribesuccAction {
    
    markView.hidden = YES;
}


//确认预约
- (void)subscribeSureAction {
    
    UITextField *nameField = (UITextField *)[subscribeView viewWithTag:190];
    UITextField *phoneField = (UITextField *)[subscribeView viewWithTag:191];

    if (nameField.text == nil || [nameField.text isEqualToString:@""]) {
        
        [APPDELEGATE showPro:@"请输入姓名"];
        return;
    }
    
    if (phoneField.text == nil || [phoneField.text isEqualToString:@""]) {
        
        [APPDELEGATE showPro:@"请输入联系方式"];
        return;
    }
    
    
    NSDictionary *dataDic = User_listsValue;
    NSString *url = [NSString stringWithFormat:@"%@member/order/appointment",Main_Url];
    NSString *number = dataDic[@"number"];
    NSString *token = dataDic[@"token"];
    NSString *nickname = [nameField.text stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

    NSDictionary *dic = @{
                            @"number":number,
                            @"token":token,
                            @"sn":self.sn,
                            @"linkname":nickname,
                            @"linktel":phoneField.text,
                            
                            };
    
    NSString *str = [ReturnSign returnSignWithDic:dic];
    NSString *md5String = [NSString stringWithFormat:@"%@%@%@",str,APPKEY_URL,url];
    
    //32位小写
    
    //    NSString *nickname = [nameText.text stringByAddingPercentEscapesUsingEncoding:
    //                          NSUTF8StringEncoding];
    
    md5String = [LCMD5Tool MD5ForLower32Bate:md5String];
    NSMutableDictionary * param = [NSMutableDictionary dictionaryWithDictionary:dic];
    [param setObject:md5String forKey:@"sign"];

    [AFHttpTool requestWihtUrl:url params:param success:^(id response) {
        
        
        if ([response[@"code"] isEqualToString:@"10000"]) {
            
            subscribeView.hidden = YES;
            successView.hidden = NO;
        }else {
            [APPDELEGATE  showPro:response[@"message"]];
        }
        
        
        
    } failure:^(NSError *err) {
        
        
        
    }];

}

//取消预约
- (void)subscribeCanceAction {
    
    markView.hidden = YES;
}


#pragma mark -- 
- (void)tabSelectAction:(UIControl*)control {
    
    [APPDELEGATE showPro:@"功能完善中"];
}

#pragma mark -- 预约房源
- (void)inquiryAction {
    
    NSDictionary *dataDic = User_listsValue;
    if (dataDic == nil) {
        
        LoginViewController *logVc = [[LoginViewController alloc] init];
        [self presentViewController:logVc animated:YES completion:nil];
        return;
    }
    
    markView.hidden = NO;
    
}
//滑动时改变导航栏样式
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGFloat hight = KWidth*346/750-64;
    CGPoint point = scrollView.contentOffset;
    CGFloat y = point.y;
    
    if (y<0) {
        navgationView.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
    }else if (y>=hight) {
        navgationView.backgroundColor = [UIColor colorWithWhite:1 alpha:1];
    }else {
//        navgationView.alpha = y*100/hight/100;
        navgationView.backgroundColor = [UIColor colorWithWhite:1 alpha:y*100/hight/100];
    }
    
}


//设置不同字体颜色
-(void)setTextColor:(UILabel *)label FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:label.text];
    //设置字号
    [str addAttribute:NSFontAttributeName value:font range:range];
    //设置文字颜色
    [str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
    
    label.attributedText = str;
}

- (void)setRichNumberWithLabel:(UILabel*)label Color:(UIColor *)color FontSize:(CGFloat)size {
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
    NSString *temp = nil;
    for(int i =0; i < [attributedString length]; i++) {
        temp = [label.text substringWithRange:NSMakeRange(i, 1)];
        if ([self isPureInt:temp]) {
            [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                             color, NSForegroundColorAttributeName,
                                             [UIFont systemFontOfSize:size],NSFontAttributeName, nil]
                                      range:NSMakeRange(i, 1)];
        }
    }
    label.attributedText = attributedString;
}

- (BOOL)isPureInt:(NSString *)string {
    NSScanner *scan = [NSScanner scannerWithString:string];
    int value;
    return [scan scanInt:&value] && [scan isAtEnd];
}

- (void)tapAvatarView {
    
    [markView endEditing:YES];
}


- (void)backAction {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)noticeAction {
    
    [APPDELEGATE showPro:@"功能完善中"];
}

- (void)matingtapAvatarView {
    
    [APPDELEGATE showPro:@"功能完善中"];
}
@end
